package tv.huan.web.controller.media;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tv.huan.common.annotation.Log;
import tv.huan.common.core.controller.BaseController;
import tv.huan.common.core.domain.AjaxResult;
import tv.huan.common.core.page.TableDataInfo;
import tv.huan.common.enums.BusinessType;
import tv.huan.common.utils.poi.ExcelUtil;
import tv.huan.media.domain.MediaAudit;
import tv.huan.media.service.IMediaAuditService;

/**
 * 媒资审核记录Controller
 * 
 * @author admin
 * @date 2020-04-03
 */
@Controller
@RequestMapping("/media/mediaAudit")
public class MediaAuditController extends BaseController
{
    private String prefix = "media";

    @Autowired
    private IMediaAuditService mediaAuditService;

    @RequiresPermissions("media:mediaAudit:view")
    @GetMapping()
    public String mediaAudit()
    {
        return prefix + "/mediaAudit";
    }

    /**
     * 查询媒资审核记录列表
     */
    @RequiresPermissions("media:mediaAudit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MediaAudit mediaAudit)
    {
        startPage();
        List<MediaAudit> list = mediaAuditService.selectMediaAuditList(mediaAudit);
        return getDataTable(list);
    }

    /**
     * 导出媒资审核记录列表
     */
    @RequiresPermissions("media:mediaAudit:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MediaAudit mediaAudit)
    {
        List<MediaAudit> list = mediaAuditService.selectMediaAuditList(mediaAudit);
        ExcelUtil<MediaAudit> util = new ExcelUtil<MediaAudit>(MediaAudit.class);
        return util.exportExcel(list, "mediaAudit");
    }

    /**
     * 新增媒资审核记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存媒资审核记录
     */
    @RequiresPermissions("media:mediaAudit:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MediaAudit mediaAudit)
    {
        return toAjax(mediaAuditService.insertMediaAudit(mediaAudit));
    }

    /**
     * 修改媒资审核记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MediaAudit mediaAudit = mediaAuditService.selectMediaAuditById(id);
        mmap.put("mediaAudit", mediaAudit);
        return prefix + "/edit";
    }

    /**
     * 修改保存媒资审核记录
     */
    @RequiresPermissions("media:mediaAudit:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MediaAudit mediaAudit)
    {
        return toAjax(mediaAuditService.updateMediaAudit(mediaAudit));
    }

    /**
     * 删除媒资审核记录
     */
    @RequiresPermissions("media:mediaAudit:remove")
    @Log(title = "媒资审核记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mediaAuditService.deleteMediaAuditByIds(ids));
    }
}
